<template>
  <div class="table-wrapper">
    <div class="search-container">
      <div class="search-wrapper">
        <span class="label">楼宇：</span>
        <el-cascader size="mini" class="large-select" v-model="params.builde_id" :options="buildingList" placeholder="请选择楼宇"
                     :props="{ checkStrictly: true, emitPath: false, multiple: false }"
                     collapse-tags
                     clearable
                     @change="getRoomClassName">
        </el-cascader>
      </div>
      <div class="search-wrapper">
        <span class="label">房间：</span>
        <el-select size="mini" v-model="params.id" placeholder="请选择房间" clearable>
          <el-option v-for="item in roomList" :key="item.name" :label="item.name" :value="item.id"></el-option>
        </el-select>
      </div>
<!--      <div class="search-wrapper">-->
<!--        <span class="label">时间类型：</span>-->
<!--        <el-select size="mini" v-model="params.time_type" placeholder="请选择时间类型" @change="changeTimeType">-->
<!--          <el-option v-for="item in timeTypeList" :key="item.text" :label="item.text" :value="item.value"></el-option>-->
<!--        </el-select>-->
<!--      </div>-->
<!--      <div class="search-wrapper">-->
<!--        <span class="label">开始时间：</span>-->
<!--        <el-date-picker-->
<!--          size="mini"-->
<!--          v-model="params.start_time"-->
<!--          :type="'date'"-->
<!--          :value-format="'yyyy-MM-dd'"-->
<!--          placeholder="选择开始时间"-->
<!--        >-->
<!--        </el-date-picker>-->
<!--      </div>-->
<!--      <div class="search-wrapper">-->
<!--        <span class="label">结束时间：</span>-->
<!--        <el-date-picker-->
<!--          size="mini"-->
<!--          v-model="params.end_time"-->
<!--          :type="'date'"-->
<!--          :value-format="'yyyy-MM-dd'"-->
<!--          placeholder="选择结束时间"-->
<!--        >-->
<!--        </el-date-picker>-->
<!--      </div>-->
    </div>
    <div class="search-container">
      <div class="search-wrapper">
        <el-button @click="getDianbiao" icon="el-icon-search" size="mini" >查询</el-button>
      </div>
    </div>
    <el-table
      :data="data"
      border
      height="calc(100% - 160px)"
      style="width: 100%">
      <el-table-column
        prop="put_date"
        label="日期">
      </el-table-column>
      <el-table-column
        prop="room_no"
        label="房间号">
      </el-table-column>
      <el-table-column
        prop="meter_no"
        label="电表编号">
      </el-table-column>
      <el-table-column
        width="200"
        prop="collect_time"
        label="冻结时间">
      </el-table-column>
      <el-table-column
        prop="PP"
        label="总">
      </el-table-column>
      <el-table-column
        prop="PP1"
        label="尖">
      </el-table-column>
      <el-table-column
        prop="PP2"
        label="峰">
      </el-table-column>
      <el-table-column
        prop="PP3"
        label="平">
      </el-table-column>
      <el-table-column
        prop="PP4"
        label="谷">
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import portal from '@/api/portal'

export default {
  name: 'FjList',
  data () {
    return {
      params: {
        id: null
        // start_time: null,
        // end_time: null
      },
      buildingList: [],
      roomList: [],
      buildingMap: {},
      timeTypeList: [
        {
          text: '天',
          value: 1
        },
        {
          text: '月',
          value: 2
        },
        {
          text: '年',
          value: 3
        }
      ],
      queryTypeList: [
        {
          text: '用电量',
          value: 1
        },
        {
          text: '缴费情况',
          value: 2
        }
      ],
      data: []
    }
  },
  created () {
    this.getRoomClass()
  },
  computed: {
  },
  mounted () {
  },
  methods: {
    // 房间信息列表
    async getDianbiao () {
      if (!this.params.id) {
        this.$message.warning('请选择房间')
        return
      }
      // if (!this.params.start_time) {
      //   this.$message.warning('请选择开始时间')
      //   return
      // }
      // if (!this.params.end_time) {
      //   this.$message.warning('请选择结束时间')
      //   return
      // }
      const params = Object.assign({}, this.params)
      delete params.builde_id
      const result = await portal.getDianbiao(params)
      if (result.data) {
        this.data = result.data
      }
    },
    // 获取楼宇
    async getRoomClass () {
      const result = await portal.getRoomClass()
      if (result.data) {
        const building = result.data
        building.forEach(e => {
          e.label = e.name
          e.value = e.id
          e.disabled = true
          e.children = e.child
          if (e.children) {
            e.children.forEach(el => {
              el.label = el.name
              el.value = el.id
              el.children = el.child
              delete el.children
              if (el.children) {
                el.children.forEach(ele => {
                  ele.label = el.name
                  ele.value = el.id
                  delete ele.children
                })
              }
            })
          }
        })
        this.buildingList = building
      }
    },
    // 获取房间
    async getRoomClassName () {
      const params = {
        id: this.params.builde_id
      }
      const result = await portal.getRoomClassName(params)
      // if (result.data) {
      //   this.roomList = result.data
      // }
      if (result.data) {
        const room = result.data
        room.forEach(e => {
          e.label = e.name
          e.value = e.id
          e.disabled = true
          if (e.children) {
            e.children.forEach(el => {
              el.label = el.name
              el.value = el.id
              delete el.children
            })
          }
        })
        this.roomList = room
      }
    },
    changeTimeType () {
      this.params.start_time = null
      this.params.end_time = null
    },
    changePage (val) {
      this.params.page = val
      this.getBusOrder()
    }
  }
}
</script>

<style scoped lang="scss">

</style>
